# Main Iteration Algorithm
# -----------------------------------------------------------------------------
function iterate_VF(ce::CE_Economy_PInf;tol_max=5e-4) 


iter, dist, dist_q_abs      = 0, 10.0, 10.0;

while iter < ce.maxiter && (dist > tol_max || iter<25)

      iter = iter+1

      # ------------------------------------------------------------------------
      # Compute expected values (includes the transition matrix)
      EWf  = compute_EV(ce, ce.Wf);
      EWd  = compute_EV(ce, ce.Wd);
      # ------------------------------------------------------------------------

      #Solve for optimal policies: bp, π, d. Update value functions
      # ------------------------------------------------------------------------
      dist_bp_abs                              = solve_main(ce, EWf);
      dist_Wf_norm, dist_Wf_abs, dist_def_norm = solve_default(ce, EWf, EWd);
      # ------------------------------------------------------------------------

      #Compute Prices
      # ------------------------------------------------------------------------
      dist_q_norm,      dist_q_abs            = compute_prices(ce);
      # ------------------------------------------------------------------------

      #Compute total (max) distance
      # ------------------------------------------------------------------------
      dist_Wq 	 = max(dist_Wf_abs, dist_q_abs);
      dist_bp	 = dist_bp_abs;
      dist    	 = dist_Wq;

      #Iterate only on prices to speed up convergence
      if iter%50==0
      for i=1:10
      dist_q_norm,      dist_q_abs       = compute_prices(ce);
      end
      end

      # ------------------------------------------------------------------------
      ratio_p=200
      if (iter%ratio_p==0  || iter==ce.maxiter)
      @printf("iter %.3g, DIST_Wf_norm %.3g, DIST_Wf_abs %.3g, DIST_q_norm %.3g, DIST_q_abs %.3g, DIST_bp_abs %.3g\n", iter, dist_Wf_norm,  dist_Wf_abs, dist_q_norm, dist_q_abs, dist_bp_abs)
      end
end # while

      #Message if reached convergence
      #------------------------------
      if iter<ce.maxiter
      println("REACHED CONVERGENCE")
      @printf("iter %.3g, distf %.3g\n", iter, dist)
      end
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------


Void
end #function
# ------------------------------------------------------------------------
